//
//  MrMIDISearchViewCtrler.m
//  MIDI
//
//  Created by EMG on 15/9/12.
//  Copyright (c) 2015年 QXSX. All rights reserved.
//

#import "MrMIDISearchViewCtrler.h"
#import "MrMIDISearchCell.h"
#import "AppConfig.h"
#import "UIViewController+NavItem.h"
#import "APIAdress.h"
#import "UserDataSingleton.h"
#import "QXNetWorkTool.h"
#import "MBProgressHUD+YC.h"
#import "MrMiDiSearchModel.h"
#import "UIImageView+WebCache.h"
#import "MrMIDIViewCtrler.h"
#import "UIViewController+Create.h"
#import "MJRefresh.h"
#import "SearchCityViewController.h"
#import "CitylistModel.h"
#import "AboutMIDIModel.h"
#import "AboutMIDISubWebViewController.h"
#import "CommFunc.h"

#define CITYKEY @"city_id"
#define JOBKEY @"major_id"
#define LVKEY @"grade_id"
#define SEXKEY @"sex"
#define NOLIMIT @""


#define LV1FLAG @"6"
#define LV2FLAG @"7"
#define LV3FLAG @"8"
#define LV4FLAG @"9"

#define MANFLAG @"1"
#define WOMANFLAG @"2"


@interface MrMIDISearchViewCtrler ()<UITableViewDataSource,UITableViewDelegate ,QXNetWorkToolDelegate , UISearchBarDelegate, SelectExamCityDeletage>
@property (weak, nonatomic) IBOutlet UIView *blackMaskUIView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *hightConstraints;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *YviewofContainTableConstraints;

@property (weak, nonatomic) IBOutlet UIView *limitUIView;

@property (weak, nonatomic) IBOutlet UIView *searchBgView;

@property (weak, nonatomic) IBOutlet UILabel *cityNameUILabel;

@property (weak, nonatomic) IBOutlet UIButton *cityElseUIBtn;
@property (weak, nonatomic) IBOutlet UIButton *cityNoLimitUIBtn;

@property (weak, nonatomic) IBOutlet UIButton *jobNolimitUIBtn;

@property (weak, nonatomic) IBOutlet UIButton *jobGitaUIBtn;

@property (weak, nonatomic) IBOutlet UIButton *jobJazzUIBtn;
@property (weak, nonatomic) IBOutlet UIButton *jobBaseUIBtn;
@property (weak, nonatomic) IBOutlet UIButton *jobMiscBaseUIBtn;

@property (weak, nonatomic) IBOutlet UIButton *lv1IUBtn;

@property (weak, nonatomic) IBOutlet UIButton *lv2UIBtn;

@property (weak, nonatomic) IBOutlet UIButton *lv3UIBtn;

@property (weak, nonatomic) IBOutlet UIButton *lv4UIBtn;

@property (weak, nonatomic) IBOutlet UIButton *lvNolimitUIBtn;

@property (weak, nonatomic) IBOutlet UIButton *sexManBtn;

@property (weak, nonatomic) IBOutlet UIButton *sexWomanBtn;
@property (weak, nonatomic) IBOutlet UIButton *sexNoLimitBtn;

@property (weak, nonatomic) IBOutlet UISearchBar *searchBar;
@property (weak, nonatomic) IBOutlet UITableView *myTableView;

@property (strong, nonatomic) MrMIDISearchCell *myCell;

@property (assign,nonatomic) BOOL isShownLimit;
@property (assign,nonatomic) BOOL isAnimatingLimit;

@property(strong,nonatomic) NSMutableDictionary * limitFlagdic;
@property(copy,nonatomic) NSString * curJob;
@property(copy,nonatomic) NSString * curLv;
@property(copy,nonatomic) NSString * curSex;
@property (assign , nonatomic) NSString *pagsize;
@property (assign , nonatomic) NSString *nowpage;

@property (copy, nonatomic) NSString *GITAFLAG;
@property (copy, nonatomic) NSString *BASEFLAG;
@property (copy, nonatomic) NSString *JAZZFLAG;
@property (copy, nonatomic) NSString *MSBASEFLAG;

@property(strong , nonatomic) QXNetWorkTool * netTool;
@property(strong , nonatomic) NSMutableArray * dataArr;
@end

@implementation MrMIDISearchViewCtrler

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.limitFlagdic = [[NSMutableDictionary alloc] init];
    [self.limitFlagdic setObject:NOLIMIT forKey:CITYKEY];
//    [self.limitFlagdic setObject:[UserDataSingleton shareInstance].currSelectExamKind forKey:JOBKEY];
        [self.limitFlagdic setObject:NOLIMIT forKey:JOBKEY];
    [self.limitFlagdic setObject:NOLIMIT forKey:LVKEY];
    [self.limitFlagdic setObject:NOLIMIT forKey:SEXKEY];


    self.cityNameUILabel.text = self.curcityName;
    
    self.curJob = NOLIMIT;
    self.curLv = NOLIMIT;
    self.curSex = NOLIMIT;
    
    self.GITAFLAG = [UserDataSingleton shareInstance].quiTa;
    self.BASEFLAG = [UserDataSingleton shareInstance].bass;
    self.JAZZFLAG = [UserDataSingleton shareInstance].JazzDrum;
    self.MSBASEFLAG = [UserDataSingleton shareInstance].musicBase;
    
    // Do any additional setup after loading the view.
    self.blackMaskUIView.hidden = YES;
    self.hightConstraints.constant = -285;
    
    self.cityNoLimitUIBtn.selected = NO;
    self.cityElseUIBtn.selected = YES;
    
    self.jobNolimitUIBtn.selected = YES;
    self.jobBaseUIBtn.selected = NO;
    self.jobGitaUIBtn.selected = NO;
    self.jobJazzUIBtn.selected = NO;
//    self.jobMiscBaseUIBtn.selected = NO;
    
    self.lv1IUBtn.selected = NO;
    self.lv2UIBtn.selected = NO;
    self.lv3UIBtn.selected = NO;
    self.lv4UIBtn.selected = NO;
    self.lvNolimitUIBtn.selected = YES;
    
    self.sexManBtn.selected = NO;
    self.sexWomanBtn.selected = NO;
    self.sexNoLimitBtn.selected = YES;

    self.isAnimatingLimit = NO;
    self.isShownLimit = NO;
    
    [self configNavigationBackAction:^{
        [self.navigationController popViewControllerAnimated:YES];
    }];
    
    if (self.isShowMrMIDISearchBgAndScreening)
    {
        self.searchBgView.hidden = NO;
        
        [self configNavigationRightString:@"筛选" textFont:[UIFont systemFontOfSize:13] textColor:MIDIColorOfNavigationBar  andAction:^{
            
            if (self.isAnimatingLimit)
            {
                return;
            }
            if (self.isShownLimit == false)
            {
                self.curcity = [self.limitFlagdic objectForKey:CITYKEY];
                self.curJob = [self.limitFlagdic objectForKey:JOBKEY];
                self.curLv = [self.limitFlagdic objectForKey:LVKEY];
                self.curSex = [self.limitFlagdic objectForKey:SEXKEY];
                self.blackMaskUIView.hidden = NO;
                [UIView animateWithDuration:0.4	 delay:0.1 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                    CGFloat offsetY = 0;
                    CGRect orgRec = self.limitUIView.frame;
                    self.limitUIView.frame = CGRectMake(orgRec.origin.x , offsetY, orgRec.size.width, orgRec.size.height);
                    self.isAnimatingLimit = YES;
                    
                } completion:^(BOOL finished) {
                    self.hightConstraints.constant = 0;
                    self.isAnimatingLimit = NO;
                    self.isShownLimit = YES;
                    [self setSearchLimitBtn];
                }];
            }
            else
            {
                [UIView animateWithDuration:0.4	 delay:0.1 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                    CGFloat offsetY = -285;
                    CGRect orgRec = self.limitUIView.frame;
                    self.limitUIView.frame = CGRectMake(orgRec.origin.x , offsetY, orgRec.size.width, orgRec.size.height);
                    
                    self.isAnimatingLimit = YES;
               
                    
                } completion:^(BOOL finished) {
                    self.hightConstraints.constant = -285;
                    
                    self.blackMaskUIView.hidden = YES;
                    
                    self.isAnimatingLimit = NO;
                    self.isShownLimit = NO;
                    //                if ([[self.limitFlagdic objectForKey:CITYKEY] isEqualToString:self.curcity]&&[[self.limitFlagdic objectForKey:JOBKEY] isEqualToString:self.curJob]&&[[self.limitFlagdic objectForKey:LVKEY] isEqualToString:self.curLv]&&[[self.limitFlagdic objectForKey:SEXKEY] isEqualToString:self.curSex]) {
                    //                    return;
                    //                }
                    //                [self collectFlagsAndUpdate];
                    
                    self.nowpage = @"1";
                    [self.dataArr removeAllObjects];
                    [self reqData];   //请求数据
                }];
            }
        } ];

        [self setShowCity:self.curcityName];
        
//        [self configNavigationRightItem1:@"筛选" textFont1:[UIFont systemFontOfSize:13]
//                              textColor1:MIDIColorOfNavigationBar
//                              andAction1:nil
//                                   Item2:@"城市"
//                               textFont2:[UIFont systemFontOfSize:13]
//                              textColor2:MIDIColorOfNavigationBar
//                              andAction2:nil];
        

        
    }
    else
    {
        self.searchBgView.hidden = YES;
        self.YviewofContainTableConstraints.constant = -self.searchBgView.frame.size.height;
    }
    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.myTableView.allowsSelection = YES;
    self.netTool = [[QXNetWorkTool alloc]init];
    self.netTool.QXNetWorkDelegate = self;
    self.dataArr = [[NSMutableArray alloc]init];
    self.nowpage = @"1";
    self.pagsize = @"6";
    self.searchBar.delegate = self;
    
    self.searchBar.layer.borderColor = RGBA(230, 232, 231, 1).CGColor;
    self.searchBar.layer.borderWidth = 1.0f;
    
    UITextField *txfSearchField = [self.searchBar valueForKey:@"_searchField"];
    txfSearchField.textColor = [UIColor grayColor];
    
    txfSearchField.layer.cornerRadius = 15.0f;
    txfSearchField.layer.masksToBounds = YES;
    txfSearchField.layer.borderColor = RGBA(219, 219, 219, 1).CGColor;
    txfSearchField.layer.borderWidth = 1.0f;


//    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)];
//    
//    [self.view addGestureRecognizer:tapGestureRecognizer];
//
//    UITapGestureRecognizer *tapGestureRecognizer1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)];
//    
//    [self.searchBgView addGestureRecognizer:tapGestureRecognizer1];
    
    
    if (self.isShowMrMIDISearchBgAndScreening)
    {
        self.myTableView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
        
        self.myTableView.footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
        
        self.searchBar.text = @"";
        [self reqData];
    }

    [self configNavigationItem];
}

#pragma mark 设置上下拉刷新

- (void)loadNewData
{
    [self.dataArr removeAllObjects];

    self.nowpage = @"1";
    
    [self reqData];
    [self.myTableView.header endRefreshing];
}

- (void)loadMoreData
{
    int i = self.nowpage.intValue;
    ++i;
    self.nowpage = [NSString  stringWithFormat:@"%d", i];
    
    [self reqData];
    [self.myTableView.footer endRefreshing];
}

-(void)tap
{
    [self.searchBar resignFirstResponder];
}

-(void)configNavigationItem
{
    self.navigationItem.title = @"搜索迷笛先生";
    [self.navigationController.navigationBar setTranslucent:NO];
    
    [self.navigationController.navigationBar
     setBackgroundImage:[UIImage imageNamed:@"bg_navigation_bar"]
     forBarMetrics:UIBarMetricsDefault];
    
    //status bar的字体为白色
    //导航栏的背景色是黑色
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName, [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0],UITextAttributeTextShadowColor,[UIFont fontWithName:@"Hiragino Sans GB" size:18.0],NSFontAttributeName,nil]];
}

- (void)setShowCity:(NSString *)cityName
{
//    UIBarButtonItem *cityBar = [[UIBarButtonItem alloc] initWithTitle:cityName style:UIBarButtonItemStyleBordered target:self action:nil];
//    UIFont *cityFont = [UIFont systemFontOfSize:13];
//    UIColor *cityColor = [UIColor whiteColor];
//    
//    NSDictionary * attributes = @{NSFontAttributeName:cityFont , NSForegroundColorAttributeName:cityColor};
//    
//    [cityBar setTitleTextAttributes:attributes forState:UIControlStateNormal];
//    
//    [cityBar setEnabled:NO];
//    
//    [self.navigationItem setRightBarButtonItems:@[self.navigationItem.rightBarButtonItem, cityBar] animated:NO];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)didHideLimit:(id)sender {
    
    if (self.isAnimatingLimit)
    {
        return;
    }
    
    
    [UIView animateWithDuration:0.4	 delay:0.1 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        CGFloat offsetY = -285;
        CGRect orgRec = self.limitUIView.frame;
        self.limitUIView.frame = CGRectMake(orgRec.origin.x , offsetY, orgRec.size.width, orgRec.size.height);
        self.isAnimatingLimit = YES;
        
    } completion:^(BOOL finished) {
        self.hightConstraints.constant = -285;
        self.blackMaskUIView.hidden = YES;
        
        self.isAnimatingLimit = NO;
        self.isShownLimit = NO;
        [self reqData];
        }];
}

-(void) collectFlagsAndUpdate
{

}


//设置搜索按钮
-(void)setSearchLimitBtn
{
    if ([self.curcity isEqual: NOLIMIT])
    {
        self.cityNoLimitUIBtn.selected = YES;
    }
    else
    {
        self.cityElseUIBtn.selected = YES;
    }
    
    if ([self.curJob isEqual:NOLIMIT])
    {
        self.jobNolimitUIBtn.selected = YES;
    }
    else if ([self.curJob isEqual:self.GITAFLAG])
    {
        self.jobGitaUIBtn.selected = YES;
    }
    else if ([self.curJob isEqual:self.BASEFLAG])
    {
        self.jobBaseUIBtn.selected = YES;
    }
    else if ([self.curJob isEqual:self.JAZZFLAG])
    {
        self.jobJazzUIBtn.selected = YES;
    }
//    else if ([self.curJob isEqual:self.MSBASEFLAG])
//    {
//        self.jobMiscBaseUIBtn.selected = YES;
//    }
    
    if ([self.curLv isEqual:NOLIMIT])
    {
        self.lvNolimitUIBtn.selected = YES;
    }
    else if ([self.curLv isEqual:self.GITAFLAG])
    {
        self.lv1IUBtn.selected = YES;
    }
    else if ([self.curLv isEqual:self.BASEFLAG])
    {
        self.lv2UIBtn.selected = YES;
    }
    else if ([self.curLv isEqual:self.JAZZFLAG])
    {
        self.lv3UIBtn.selected = YES;
    }
    else if ([self.curLv isEqual:self.MSBASEFLAG])
    {
        self.lv4UIBtn.selected = YES;
    }
    
    if ([self.curSex isEqual:NOLIMIT])
    {
        self.sexNoLimitBtn.selected = YES;
    }
    else if ([self.curSex isEqual:self.GITAFLAG])
    {
        self.sexManBtn.selected = YES;
    }
    else if ([self.curSex isEqual:self.BASEFLAG])
    {
        self.sexWomanBtn.selected = YES;
    }

}


- (IBAction)didClick_HowToBecameMrMIDI:(id)sender {
    

    [MBProgressHUD showMessage:@"正在加载" toView:self.view];
    
    QXNetWorkTool *tool = [[QXNetWorkTool alloc]init];
    
    tool.QXNetWorkDelegate = self;
    
    [tool GetDataFromServerWithPostMethodandInterfaceName:AboutMIDIInterface 	andParameter:@[@{@"article_id":@"become_midi_sir"}] tag:2];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 122;//[self.myCell getHeight];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    self.myCell = [MrMIDISearchCell cellWithTableView:tableView];
    [self configCell:indexPath.row cell:self.myCell];
    return self.myCell;
}

#pragma mark - Table View Delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MrMiDiSearchModel *data = [self.dataArr objectAtIndex:indexPath.row];
    MrMIDIViewCtrler * vc = [MrMIDIViewCtrler create];
    [vc setMrMidiId:data.id];
    [self.navigationController pushViewController:vc animated:YES];
}


-(void)configCell:(NSInteger)row cell:(MrMIDISearchCell*)mycell
{
    if ([self.dataArr count] <= 0)
        return;
    
    MrMiDiSearchModel *data = [self.dataArr objectAtIndex:row];
    if(data == nil)
        return;
    [mycell.nameLb setText:data.real_name];
    
    if (![data.head_img isEqualToString:@""])
    {
        [mycell.headIcon sd_setImageWithURL:[NSURL URLWithString:data.head_img]];
    }
    if([data.highest_level isEqual:@"初级"])
    {
        [mycell.midilevelUILabel setText:@"初级迷笛先生"];
    }
    else if([data.highest_level isEqual:@"中级"])
    {
        [mycell.midilevelUILabel setText:@"中级迷笛先生"];
    }
    else if([data.highest_level isEqual:@"高级"])
    {
        [mycell.midilevelUILabel setText:@"高级迷笛先生"];
    }
    else if([data.highest_level isEqual:@"特级"])
    {
        [mycell.midilevelUILabel setText:@"特级迷笛先生"];
    }
    
    [mycell.professionalUILabel setText:data.major_name];
    
    [mycell.loacationUILabel setText:data.name];
    
    [mycell.introLb setText:data.mr_introduce];
}


//#pragma mark LIMIT

//#pragma mark city

- (IBAction)didClick_NoLimitCityBtn:(id)sender {
    
    self.curcity = @"";
    self.curcityName = @"";
//    self.cityNameUILabel.textColor = [UIColor grayColor];
    self.cityNameUILabel.text = @"全国";
    self.cityNoLimitUIBtn.selected = YES;
    self.cityElseUIBtn.selected = NO;
    [self.limitFlagdic setObject:NOLIMIT forKey:CITYKEY];
    
    [self setShowCity:@"全国"];
}

- (IBAction)didClick_ElseCityBtn:(id)sender
{
    SearchCityViewController *obj = [SearchCityViewController create];
    obj.delegate = self;
    [self.navigationController pushViewController:obj animated:YES];
}

-(void)setExamCity:(NSString *)city
{
    self.cityElseUIBtn.selected = YES;
    self.cityNoLimitUIBtn.selected = NO;
    
    self.cityNameUILabel.text = city;
    
    NSMutableArray *data = [UserDataSingleton shareInstance].cityList;
    
    for (int i = 0; i < [data count]; ++i)
    {
        CitylistModel *model = [data objectAtIndex:i];
        
        if (model && [model.name isEqualToString:city])
        {
            self.curcity = model.id;
            self.curcityName = model.name;
            
            [self.limitFlagdic setObject:self.curcity forKey:CITYKEY];
            
            [self setShowCity:self.curcityName];
            
            break;
        }
    }
}

//#pragma mark job

- (IBAction)didClick_JobNolimitBtn:(id)sender
{
    self.jobNolimitUIBtn.selected = YES;
    self.jobBaseUIBtn.selected = NO;
    self.jobGitaUIBtn.selected = NO;
    self.jobJazzUIBtn.selected = NO;
//    self.jobMiscBaseUIBtn.selected = NO;
    self.curJob = NOLIMIT;
    if([self.limitFlagdic objectForKey:JOBKEY])
    {
        [self.limitFlagdic removeObjectForKey:JOBKEY];
    }
}
- (IBAction)didClick_JazzBtn:(id)sender {
    self.jobNolimitUIBtn.selected = NO;
    self.jobBaseUIBtn.selected = NO;
    self.jobGitaUIBtn.selected = NO;
    self.jobJazzUIBtn.selected = YES;
//    self.jobMiscBaseUIBtn.selected = NO;
    self.curJob = self.JAZZFLAG;
    [self.limitFlagdic setObject:self.JAZZFLAG forKey:JOBKEY];
}
- (IBAction)didClick_BaseBtn:(id)sender {
    self.jobNolimitUIBtn.selected = NO;
    self.jobBaseUIBtn.selected = YES;
    self.jobGitaUIBtn.selected = NO;
    self.jobJazzUIBtn.selected = NO;
//    self.jobMiscBaseUIBtn.selected = NO;
    [self.limitFlagdic setObject:self.BASEFLAG forKey:JOBKEY];
}
- (IBAction)didClick_GitaBtn:(id)sender {
    self.jobNolimitUIBtn.selected = NO;
    self.jobBaseUIBtn.selected = NO;
    self.jobGitaUIBtn.selected = YES;
    self.jobJazzUIBtn.selected = NO;
//    self.jobMiscBaseUIBtn.selected = NO;
    self.curJob= self.GITAFLAG;
    [self.limitFlagdic setObject:self.GITAFLAG forKey:JOBKEY];
}
- (IBAction)didClick_MiscBaseBtn:(id)sender {
    self.jobNolimitUIBtn.selected = NO;
    self.jobBaseUIBtn.selected = NO;
    self.jobGitaUIBtn.selected = NO;
    self.jobJazzUIBtn.selected = NO;
//    self.jobMiscBaseUIBtn.selected = YES;
    self.curJob = self.MSBASEFLAG;
    [self.limitFlagdic setObject:self.MSBASEFLAG forKey:JOBKEY];
}

//#pragma mark Level

- (IBAction)didClick_lvNolimitBtn:(id)sender {
    self.lv1IUBtn.selected = NO;
    self.lv2UIBtn.selected = NO;
    self.lv3UIBtn.selected = NO;
    self.lv4UIBtn.selected = NO;
    self.lvNolimitUIBtn.selected = YES;
    if([self.limitFlagdic objectForKey:LVKEY])
    {
        [self.limitFlagdic removeObjectForKey:LVKEY];
    }
    
}

- (IBAction)didClick_1LvBtn:(id)sender {
    self.lv1IUBtn.selected = YES;
    self.lv2UIBtn.selected = NO;
    self.lv3UIBtn.selected = NO;
    self.lv4UIBtn.selected = NO;
    self.lvNolimitUIBtn.selected = NO;
    self.curLv = LV1FLAG;
    [self.limitFlagdic setObject:LV1FLAG forKey:LVKEY];
}


- (IBAction)didClick_2LvBtn:(id)sender {
    self.lv1IUBtn.selected = NO;
    self.lv2UIBtn.selected = YES;
    self.lv3UIBtn.selected = NO;
    self.lv4UIBtn.selected = NO;
    self.lvNolimitUIBtn.selected = NO;
    self.curLv = LV2FLAG;
    [self.limitFlagdic setObject:LV2FLAG forKey:LVKEY];
    
}

- (IBAction)didClick_3LvBtn:(id)sender {
    self.lv1IUBtn.selected = NO;
    self.lv2UIBtn.selected = NO;
    self.lv3UIBtn.selected = YES;
    self.lv4UIBtn.selected = NO;
    self.lvNolimitUIBtn.selected = NO;
    self.curLv = LV3FLAG;
    [self.limitFlagdic setObject:LV3FLAG forKey:LVKEY];
}

- (IBAction)didClick_4LvBtn:(id)sender {
    self.lv1IUBtn.selected = NO;
    self.lv2UIBtn.selected = NO;
    self.lv3UIBtn.selected = NO;
    self.lv4UIBtn.selected = YES;
    self.lvNolimitUIBtn.selected = NO;
    self.curLv = LV4FLAG;
    [self.limitFlagdic setObject:LV4FLAG forKey:LVKEY];
}

//#pragma mark Sex

- (IBAction)didClick_sexNoLimit:(id)sender {
    self.sexNoLimitBtn.selected = YES;
    self.sexManBtn.selected = NO;
    self.sexWomanBtn.selected = NO;
    self.curSex = NOLIMIT;
    if([self.limitFlagdic objectForKey:SEXKEY])
    {
        [self.limitFlagdic removeObjectForKey:SEXKEY];
    }
}
- (IBAction)didClick_Womanbtn:(id)sender {
    self.sexNoLimitBtn.selected = NO;
    self.sexManBtn.selected = NO;
    self.sexWomanBtn.selected = YES;
    self.curSex = WOMANFLAG;
    [self.limitFlagdic setObject:WOMANFLAG forKey:SEXKEY];
}

- (IBAction)didClick_Mantn:(id)sender {
    self.sexNoLimitBtn.selected = NO;
    self.sexManBtn.selected = YES;
    self.sexWomanBtn.selected = NO;
    self.curSex = MANFLAG;
    [self.limitFlagdic setObject:MANFLAG forKey:SEXKEY];
}

-(void)GetSuccessResponse:(id)Response andTag:(int)tag
{
    [MBProgressHUD hideHUDForView:self.view];
    
    if(tag == 1)
    {
        if (self.isShowMrMIDISearchBgAndScreening == YES)
        {
            
        }
        else
        {
            [self.dataArr removeAllObjects];
        }
        
        for(NSDictionary * dic in Response)
        {
            MrMiDiSearchModel *item = [MrMiDiSearchModel MyModelWithDict:dic];
            [self.dataArr addObject:item];
        }
        
        [self.myTableView reloadData];
        return;
    }
    
    if (tag == 2)
    {
        AboutMIDIModel *model;
        for (NSDictionary *dic in Response)
        {
            model = [AboutMIDIModel AboutMIDIModelWithDict:dic];
            
            break;
        }
        
        AboutMIDISubWebViewController *obj = [AboutMIDISubWebViewController create];
        obj.title = @"成为迷笛先生介绍";
        obj.url = model.url;
        
        [self.navigationController pushViewController:obj animated:YES];
        
        return;
    }
}

-(void)GetFailResponse:(id)Response andTag:(int)tag
{
	[MBProgressHUD hideHUDForView:self.view];
    
    if (Response == nil)
        return;
    
    NSString *message = Response;
    
    [MBProgressHUD showError:message toView:self.view];
}

//请求搜索列表数据
-(void)reqData
{
    if ([CommFunc isPureInt:self.searchBar.text])
    {
        //按midi id搜索
        [self.limitFlagdic setObject:self.searchBar.text forKey:@"midiId"];
        
        [self.limitFlagdic setObject:@"" forKey:@"name"];
    }
    else
    {
        //按名字搜索
        [self.limitFlagdic setObject:@"" forKey:@"midiId"];
        [self.limitFlagdic setObject:self.searchBar.text forKey:@"name"];
    }
    
    [self.limitFlagdic setObject:self.curcity forKey:CITYKEY];
    [self.limitFlagdic setObject:self.nowpage forKey:@"nowpage"];
    [self.limitFlagdic setObject:self.pagsize forKey:@"pagesize"];
    
    [MBProgressHUD showMessage:@"正在加载" toView:self.view];
    [self.netTool GetDataFromServerWithPostMethodandInterfaceName:MrMidiSearchInterface andParameter:@[self.limitFlagdic] tag:1];
}

//#pragma mark searchBar delegate

-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    [self.searchBar resignFirstResponder];
    
    [self searchById];
}

- (void)searchBarTextDidBeginEditing:(UISearchBar *) searchBar
{
    //支持空搜索
    if (self.isShowMrMIDISearchBgAndScreening == YES)
    {
        UITextField *searchBarTextField = nil;
        NSArray *views = ([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0) ? searchBar.subviews : [[searchBar.subviews objectAtIndex:0] subviews];
        for (UIView *subview in views)
        {
            if ([subview isKindOfClass:[UITextField class]])
            {
                searchBarTextField = (UITextField *)subview;
                break;
            }
        }
        searchBarTextField.enablesReturnKeyAutomatically = NO;
    }
}

-(void)searchById
{
    if (self.isShowMrMIDISearchBgAndScreening)
    {
        [self.dataArr removeAllObjects];
        
        self.nowpage = @"1";
        [self reqData];
        
        return;
    }
    else
    {
        if(self.searchBar.text.length <= 0)
        {
            return;
        }
        
        [self reqData];
//        
//        if ([CommFunc isPureInt:self.searchBar.text])
//        {
//            //按midi id搜索
//            [self.limitFlagdic setObject:self.searchBar.text forKey:@"midiId"];
//            
//            [self.limitFlagdic setObject:@"" forKey:@"name"];
//        }
//        else
//        {
//            //按名字搜索
//            [self.limitFlagdic setObject:@"" forKey:@"midiId"];
//            [self.limitFlagdic setObject:self.searchBar.text forKey:@"name"];
//        }
//        
//        
//        [self.limitFlagdic setObject:self.curcity forKey:CITYKEY];
//        [self.limitFlagdic setObject:self.nowpage forKey:@"nowpage"];
//        [self.limitFlagdic setObject:self.pagsize forKey:@"pagesize"];
//        
//        [MBProgressHUD showMessage:@"正在加载" toView:self.view];
//        [self.netTool GetDataFromServerWithPostMethodandInterfaceName:MrMidiSearchInterface andParameter:@[self.limitFlagdic] tag:1];
    }
}

@end










